

<?php
session_start();

$defecto = "images/profile_m.gif";
$Ok = isset($_FILES["archivo"]);
$url = ($Ok) ? $_FILES["archivo"]["tmp_name"] : $defecto;
list($anchura, $altura, $tipoImagen, $atributos) = getimagesize($url);
$error = (isset($atributos)) ? 0 : 1;
$los_tipos = array("gif", "jpg", "png");
$tipo = ($Ok) ? "image/" . $los_tipos[$tipoImagen - 1] : "image/gif";
$fichero = ($Ok && ($error == 0)) ? $_FILES["archivo"]["name"] : $defecto;
$tam = filesize($url);

//$maxTam =  100000;
///$maxAncho = 640;
//$maxAlto = 480;
//$error += ($tam <= $maxTam) ? 0 : 2;
$ancho = ($error == 1) ? 0 : $anchura;
$alto = ($error == 1) ? 0 : $altura;

$datos = $url;
$onload = ($Ok) ? "onload='parent.datosImagen($tam, $ancho, $alto, $error)'" : '';
$datos_imagen = fread(fopen($datos, "rb"), filesize($datos));
$_SESSION["cont"] = $datos_imagen;
$_SESSION["tipo"] = ($error == 0) ? $tipo : "image/gif";

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title></title>
        <style>
            *{
                margin:0;
                padding:0;
            }

            body{
                background-color:#393939;
                color:#fff;
                font-family: Helvetica, Calibri, Arial, sans-serif;
                font-size:12px;
                padding:2px;
                /*		padding:10px;*/
            }



            #crop-holder {
                width:148px;
                /*		margin:10px auto;*/

            }

            #crop-iholder {
                height:148px;
                width:148px;
                overflow:hidden;
                cursor:move;
                background-image: url('images/profile_m.gif');
                background-repeat: no-repeat;
            }
            #imgPhoto{


            }
        </style>
        <script src="js/mootools-1.2-core-yc.js" type="text/javascript"></script>
        <script src="js/mootools-1.2-more-drag.js" type="text/javascript"></script>
    </head>
    <body>


        <div id="crop-holder">
            <div id="crop-iholder">
                <?
                if($_GET['upload']=="true"){
                
                    echo '<img id="imgPhoto" src="previendo.php?dato='. $fichero.'"  />';
                }else{
                    echo '<img id="imgPhoto" src="logica/ClassPersona.php?accion=traerImagenPerfil" />';
                }
                
                ?>
                
                
            </div>
        </div>



        <script type="text/javascript">
            
              document.cookie = "top=" +0;
              document.cookie = "left=" + 0;
            
            document.getElementById('imgPhoto').style.marginTop = "<?php echo $_GET['top']; ?>" + "px";
            document.getElementById('imgPhoto').style.marginLeft = "<?php echo $_GET['left']; ?>" + "px";
            //<![CDATA[
            var cropImage = function(target, container, coordinateContainer, topCoord, leftCoord){
                var img = $(target);
                var imgSizeRatio = img.getSize().x / img.getSize().y;
                var desiredRatio = 148 / 148;
                //                	if (imgSizeRatio > desiredRatio) {
                //                		img.setStyle('height','150px');
                //                	}else{
                //                		img.setStyle('width','150px');	
                //                	}
                var myDragScroller = new Drag(container, {
                    
                    snap:0,
                    style: false,
                    invert: true,
                    modifiers: {x: 'scrollLeft', y: 'scrollTop'},
                    onComplete: function(el){
                        
                        document.cookie = "top=" + img.getCoordinates($(coordinateContainer)).top;
                        document.cookie = "left=" + img.getCoordinates($(coordinateContainer)).left;
                       

                    }
                });
            }

             window.addEvent('load', function(){ 
             // important do not use domReady since we want the image to be loaded
                document.ondragstart = function () { return false; }; 
                ////IE drag hack 
                 <?
                if($_GET['upload']=="true"){
                
                echo "cropImage('imgPhoto', 'crop-iholder', 'crop-holder', 'hdnInpTop', 'hdnInpLeft')";
                }
                ?>
                
            });
           
                
                
            
            //]]>	
        </script>


    </body>
</html>
